package com.gavindon.android.widget.recyclerview

import android.content.Context
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.recyclerview.widget.RecyclerView
import com.gavindon.android.entity.VideoTreeResp

/**
 * description:
 * Created by liNan on  2022-2-9 20:56
 */
abstract class BaseRvAdapter<T, VH : BaseViewHolder>(
    @LayoutRes private val layoutResId: Int,
    data: List<VideoTreeResp>? = null
) : RecyclerView.Adapter<VH>() {
    val mData = data
    val context: Context?
        get() {
            return mRecyclerView?.context
        }
    private var mRecyclerView: RecyclerView? = null
    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        this.mRecyclerView = recyclerView
        super.onAttachedToRecyclerView(recyclerView)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return BaseViewHolder(parent.getItemView(layoutResId)) as VH
    }

    override fun getItemCount() = mData?.size ?: 0


}